package testplugineditor.editors;

import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.IWhitespaceDetector;
import org.eclipse.jface.text.rules.IWordDetector;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.SingleLineRule;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;

class FicheReleaseScanner extends RuleBasedScanner {
	
    public FicheReleaseScanner(ColorManager manager) {
       //Token keyword = new Token(new TextAttribute(manager.getColor(ColorConstants.PROC_INSTR)));
       Token comment = new Token(new TextAttribute(manager.getColor(ColorConstants.COMMENT)));
       Token string  = new Token(new TextAttribute(manager.getColor(ColorConstants.STRING)));
       //Token hexaToken	= new Token(new TextAttribute(manager.getColor(ColorConstants.HEXA)));
       Token sqlToken	= new Token(new TextAttribute(manager.getColor(ColorConstants.SQL)));
       Token mantisToken	= new Token(new TextAttribute(manager.getColor(ColorConstants.MANTIS)));
       Token sectionToken	= new Token(new TextAttribute(manager.getColor(ColorConstants.SECTION)));
       //Token section  = new Token(new TextAttribute(manager.getColor(ColorConstants.SECTION)));
       //add tokens for each reserved word
       //IToken defaultToken = new Token(new TextAttribute(ColorConstants.TAG));
       //Color color = ColorManager.getColor( ColorConstants.TAG );
       Display display = Display.getCurrent();
       
       
       //Rules keyword
       //TextAttribute taKeyWord = new TextAttribute(display.getSystemColor(SWT.COLOR_DARK_RED), null, SWT.BOLD );       
       Token keyWordToken = new Token(new TextAttribute(manager.getColor(ColorConstants.KEYWORD)));
       WordRule keyWordRule = new WordRule(new IWordDetector() {
           public boolean isWordStart(char c) {
        	   return Character.isJavaIdentifierStart(c); 
           }
           public boolean isWordPart(char c) {   
           	return Character.isJavaIdentifierPart(c); 
           }
        });      
       keyWordRule.addWord("description", keyWordToken);
       keyWordRule.addWord("version", keyWordToken);
       keyWordRule.addWord("date", keyWordToken);
       keyWordRule.addWord("prévue", keyWordToken);
     //Fin Rules keyword
       
       
      
       //IToken sectionToken = new Token(taKeyWord);
       
       //Rules keyword
       /*
       TextAttribute tasection = new TextAttribute(display.getSystemColor(SWT.COLOR_DARK_RED), null, SWT.BOLD );       
      
       WordRule sectionRule = new WordRule(new IWordDetector() {
           public boolean isWordStart(char c) {
        	   //System.out.println("!" + c);
        	   if (c == '[' ) return true ;
        	   return false ; 
           }
           public boolean isWordPart(char c) {   
        	   if (c == ']' ) return false ;
        	   return true ; 
           }
        });      
       sectionRule.addWord("[GENERAL", sectionToken);
       sectionRule.addWord("[PROBLEMS AND SOLUTION", sectionToken);
       sectionRule.addWord("[WARNING", sectionToken);
       sectionRule.addWord("[VERSION", sectionToken);
       */
       
     //Fin Rules keyword
       //HexNumberRule hexNumberRule = new HexNumberRule(hexaToken) ;
       MantisNumberRule mantisNumberRule = new MantisNumberRule(mantisToken);
       FichierSQLRule FichierSQLRule = new FichierSQLRule(sqlToken) ;
       SectionFicheRealeaseRule sectionFicheRealeaseRule = new SectionFicheRealeaseRule(sectionToken);
       
       setRules(new IRule[] {
          keyWordRule,
          sectionFicheRealeaseRule,
          //sectionRule,
          FichierSQLRule,
          mantisNumberRule,
          new SingleLineRule("#", null, comment),
          new SingleLineRule("\"", "\"", string, '\\'),
          new SingleLineRule("'", "'", string, '\\'),
          //hexNumberRule,
          new WhitespaceRule(new IWhitespaceDetector() {
             public boolean isWhitespace(char c) {
                return Character.isWhitespace(c);
             }
          }),
          
       });
    }
    
 }
